package chapter01;

public class Login{
	
	String[] userDB = {"admin^123456","henry^123456","sara^888888"}; 

    public void login(String username, String password) {
		for (int i = 0; i < userDB.length; i++) {
			byte[] b = userDB[i].getBytes();
			String u = "";
			String p = "";
			for (int j = 0; j < b.length; j++) {
				if ('^' == b[j]) {
					u = userDB[i].substring(0, j);
					p = userDB[i].substring(j + 1, userDB[i].length());
					break;
				}
			}
			if (u.equals(username) && p.equals(password)) {
				System.out.println("用户登录成功！");
				return;
			} else {
				if (i == userDB.length - 1) {
					System.out.println("用户名或密码错误！");
				}
			}
		}
}


        public static void main(String[] args) {
        Login ln = new Login();
        ln.login("henry","123456");
        }
    
}